﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TresselLS
{
    public partial class UserInputForm : Form
    {
       /*#
       Variable Name: isString
       Module Where Defined: UserInputForm
       Data Type: bool
       Local or Global: Global
       Purpose: determines whether the form is looking for a string or integer
       #*/
        private bool isString = false;
        /*#
        Variable Name: formReference
        Module Where Defined: UserInputForm
        Data Type: SimulatorForm
        Local or Global: Global
        Purpose: the reference to the parent form
        #*/
        private SimulatorForm formReference;
        public UserInputForm(bool isStringInput, SimulatorForm formRefParam)
        {
            /*!
            Procedure Name: UserInputForm
            Description: intializes the UserInputForm depending on whether the user is entering a string or number
            Input Parameters: bool isStringInput, SimulatorForm formRefParam
            Output Parameters: none
            Error Conditions Tested:
            Error Messages Generated:
            Original Author: Steve Rudy
            Procedure Creation Date: 11/24/2009
            Modification Log:
            Coding Standards Met: SR
            Testing Standards Met: RM
            !*/
            InitializeComponent();
            this.isString = isStringInput;
            this.formReference = formRefParam;
            if (isString)
            {
                this.Text = "Enter a string";
                this.inputTextBox.MaxLength = 3;
            }
        }

        private void inputTextBoxTextChanged(object sender, EventArgs e)
        {
            /*!
            Procedure Name: inputTextBoxTextChanged
            Description: validates the input and determines whether the user can press enter
            Input Parameters: object sender, EventArgs e
            Output Parameters: none
            Error Conditions Tested:
            Error Messages Generated:
            Original Author: Steve Rudy
            Procedure Creation Date: 11/24/2009
            Modification Log:
            Coding Standards Met: SR
            Testing Standards Met: RM
            !*/
            if (inputTextBox.Text.Length > 0)
            {
                if (isString)
                {
                    enterInputButton.Enabled = true;
                }
                else
                {
                    /*#
                    Variable Name: isNumber
                    Module Where Defined: inputTextBoxTextChanged
                    Data Type: bool
                    Local or Global: Local
                    Purpose: remembers if the input is a number or not
                    #*/
                    bool isNumber = true;
                    try
                    {
                        int.Parse(inputTextBox.Text);
                    }
                    catch
                    {
                        isNumber = false;
                    }
                    if (!isNumber)
                    {
                        errorLabel.Text = "Must enter a number";
                        errorLabel.Visible = true;
                        enterInputButton.Enabled = false;
                    }
                    else
                    {
                        errorLabel.Visible = false;
                        enterInputButton.Enabled = true;
                    }
                }
            }
            else
            {
                enterInputButton.Enabled = false;
            }
        }

        private void enterInputButtonClick(object sender, EventArgs e)
        {
            /*!
            Procedure Name: enterInputButtonClick
            Description: returns the value the user typed to the simulator and closes the input form
            Input Parameters: object sender, EventArgs e
            Output Parameters: none
            Error Conditions Tested:
            Error Messages Generated:
            Original Author: Steve Rudy
            Procedure Creation Date: 11/24/2009
            Modification Log:
            Coding Standards Met: SR
            Testing Standards Met: RM
            !*/
            if (isString)
            {
                this.formReference.inputString = inputTextBox.Text;
            }
            else
            {
                this.formReference.inputNum = int.Parse(inputTextBox.Text);
            }
            this.Close();
        }
    }
}
